@extends('admin.layout.common')
@section('content')
    <link rel="stylesheet" href="{{url('/css/finance/add_statement.css')}}">
    <link rel="stylesheet" href="{{url('/css/app.css')}}">
    <div class="content">
        <h1 class="h1">财务记账中心</h1>
        <!-- 公共结束 -->
        <p>
            <button type="button" class="layui-btn layui-btn-radius add_SP">增加SP</button>
        </p>
        <div style="text-align: center;">
            @include('flash::message')
        </div>
        <table border="1">
            <tr>
                <th>ID</th>
                <th>SP名称</th>
                <th>收益类型</th>
                <th>操作</th>
                <th>操作SP</th>
            </tr>
            @foreach($list as $v)
                @if(count($v['type']))
                    @foreach($v['type'] as $k => $vv)
                        <tr>
                            @if($k == 0)
                                <td rowspan="{{count($v['type'])}}">{{$v['id']}}</td>
                                <td rowspan="{{count($v['type'])}}">{{$v['platform']}}</td>
                            @endif
                            <td>{{$vv['type']}}</td>
                            <td onclick="delOne({{$vv['id']}})" class="point">删除单条</td>
                            @if($k == 0)
                                <td rowspan="{{count($v['type'])}}">
                                    <button type="button" class="layui-btn layui-btn-radius"
                                            onclick="addOne({{$v['id']}})">添加
                                    </button>
                                    <button type="button" class="layui-btn layui-btn-radius layui-btn-danger" onclick="del({{$v['id']}})">删除SP
                                    </button>
                                </td>
                            @endif
                        </tr>
                    @endforeach
                @else
                    <tr>
                        <td rowspan="">{{$v['id']}}</td>
                        <td rowspan="">{{$v['platform']}}</td>
                        <td></td>
                        <td></td>
                        <td rowspan="">
                            <button type="button" class="layui-btn layui-btn-radius" onclick="addOne({{$v['id']}})">添加
                            </button>
                            <button type="button" class="layui-btn layui-btn-radius layui-btn-danger" onclick="del({{$v['id']}})">删除SP</button>
                        </td>
                    </tr>
                @endif

            @endforeach
        </table>
        {{$list->links()}}
    </div>
    <script>
      $('.add_SP').on('click', function () {
        layer.open({
          type: 2,
          skin: 'layui-layer-rim',
          area: ['550px', '350px'],
          content: '{{url('/admin/financeAddSp')}}',
          end: function () {
            location.reload();
          }
        })
      });

      function addOne(id) {
        layer.open({
          type: 2,
          skin: 'layui-layer-rim',
          area: ['550px', '350px'],
          content: '{{url('/admin/financeAddOne')}}' + '/' + id,
          end: function () {
            location.reload();
          }
        })
      }

      function del(id) {
        location.href = '{{url('/admin/delSp').'/'}}' + id
      }

      function delOne(id) {
        location.href = '{{url('/admin/delOne').'/'}}' + id;
      }
    </script>
@endsection